package org.kjtc.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.kjtc.entity.ChargingStation;
import org.kjtc.service.StationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ Author     ：Yellowong
 * @ Date       ：Created in 11:17 2018/12/6
 * @ Description：
 */
@Controller
public class StationController {

    @Autowired
    private StationService stationService;

    @Autowired
    RedisTemplate<String, Object> redisTemplate;

    @RequestMapping("/station")
    public String main(){
        return "station";
    }

    @RequestMapping("/getStationInfo")
    @ResponseBody
    public Object getStationList(ChargingStation station,
                                       @RequestParam(value = "queryCondition") String condition,
                                       @RequestParam(value = "queryType") String type,
                                       @RequestParam(value = "pageNumber", defaultValue = "1") Integer pageNumber,
                                       @RequestParam(value = "pageSize", defaultValue="10") Integer pageSize) {

        if (!condition.equals("")) {
            switch (type) {
                case "站编号" :
                    station.setChargingStationID(condition);
                    break;
                case "充电站名称" :
                    station.setChargingStationName(condition);
                    break;
                case "运营公司" :
                    station.setBusinessID(condition);
                    break;
                case "建设状态" :
                    station.setConstructStatus(Integer.parseInt(condition));
                    break;
            }
        }
        PageHelper.startPage(pageNumber, pageSize);

        List<ChargingStation> stationList = stationService.getStationList(station);

        PageInfo pageInfo = new PageInfo(stationList);

        return pageInfo;
    }

    /* 统计建设状态 0、1、2、3分别代表已投运、建设中、规划中、已禁用 */
    @RequestMapping("/stationStatusStatistics")
    @ResponseBody
    public List ConstructionStateStatistics() {

        return stationService.stationStatusStatistics();
    }
}
